package m202311.d03;

/**
 * @@author: 爱做梦的锤子
 * @date: 2023/11/3 21:11
 */
public class Q121 {

    public static void main(String[] args) {
        int i = new Q121().maxProfit(new int[]{5, 2, 10, 1, 7});
        System.out.println(i);
    }

    public int maxProfit(int[] prices) {
        int min = prices[0];
        int result = 0;
        for (int price : prices) {
            if (price < min) {
                min = price;
            } else {
                result = Math.max(price - min, result);
            }
        }
        return result;
    }
}
